package mdm.led;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import mdm.led.common.LocalConfig;

/**
 * 拦截器配置
 * 
 * @author :heqifang
 * @date :2018年11月11日
 * @explain :
 */
@Configuration
public class ServletContextConfig extends WebMvcConfigurationSupport {

	@Autowired
	protected LocalConfig localConfig;
	/**
	 * 发现如果继承了WebMvcConfigurationSupport，则在yml中配置的相关内容会失效。 需要重新指定静态资源
	 * 
	 * @param registry
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// 存放图片的路径
		String imgPath = localConfig.getPicture_upload();
		registry.addResourceHandler("/**")
		.addResourceLocations("classpath:/static/");
		registry.addResourceHandler("swagger-ui.html")
		.addResourceLocations("classpath:/META-INF/resources/");
		registry.addResourceHandler("/webjars/**")
		.addResourceLocations("classpath:/META-INF/resources/webjars/");
		registry.addResourceHandler("/**")
		.addResourceLocations("file:"+imgPath);
		super.addResourceHandlers(registry);

	}

	/**
	 * 配置servlet处理
	 */
	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
		configurer.enable();
	}

}